/*
 * readtm.cpp
 *
 *  Created on: 2020-6-2
 *      Author: root
 */

#include "readtm.h"

//int main111(int argc,char *argv[])


 int readRTC_TM(struct rtc_time *p_rtc_tm)
{
        int retval,fd;
        struct rtc_time rtc_tm=*p_rtc_tm;
        fd=open("/dev/rtc",O_RDONLY);
        if(fd==-1)
        {
        	perror("error open /dev/rtc");
        	exit(EXIT_FAILURE);
        }
        retval=ioctl(fd,RTC_RD_TIME,&rtc_tm);

        if(retval==-1)
        {
        	perror("error RTC_RD_TIME ioctl");
        	exit(EXIT_FAILURE);
        }
        *p_rtc_tm=rtc_tm;

 //       printf("year=%d mon=%d  day=%d  sec=%d,min=%d,hour=%d\n",rtc_tm.tm_year+1900,rtc_tm.tm_mon,rtc_tm.tm_wday,rtc_tm.tm_sec,rtc_tm.tm_min,rtc_tm.tm_hour);
        close(fd);
     //   exit(EXIT_SUCCESS);
        return 0;


}
